//https://leetcode.cn/problems/two-sum/?envType=study-plan-v2&envId=top-100-liked

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) 
    {
        vector<int> ret;
        unordered_map<int,int> hash;    
        for(int i=0;i<nums.size();i++)
        {
            if(hash.count(target-nums[i])) return {i,hash[target-nums[i]]};
            else hash[nums[i]]=i;
        }


        return {-1,-1};
    }
};

//https://leetcode.cn/problems/group-anagrams/?envType=study-plan-v2&envId=top-100-liked

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) 
    {
        vector<vector<string>> ret;
        unordered_map<string,vector<string>> hash;
        for(auto &e:strs)
        {
            string temp=e;
            sort(temp.begin(),temp.end());
            hash[temp].push_back(e);
        }    

        for(auto &[a,b]:hash)
        {
            ret.push_back(b);
        }

        return ret;
    }
};

//https://leetcode.cn/problems/longest-consecutive-sequence/?envType=study-plan-v2&envId=top-100-liked

class Solution {
public:
    int longestConsecutive(vector<int>& nums) 
    {
        unordered_set<int> hash;
        for(auto &e:nums)
        {
            hash.insert(e);
        } 

        int ret=0;
        int pos=0;
        int cur=0;

        for(auto &e:hash)
        {
            if(!hash.count(e-1))
            {
                pos=e;
                cur=0;
            }
            while(hash.count(pos))
            {
                pos++;
                cur++;
            }

            ret=max(ret,cur);
        }

        return ret;
    }
};

//https://leetcode.cn/problems/move-zeroes/submissions/641778546/?envType=study-plan-v2&envId=top-100-liked

class Solution {
public:
    void swap(int & x,int &y)
    {
        int z=x;
        x=y;
        y=z;
    }
    void moveZeroes(vector<int>& nums) 
    {
        int dest=-1;
        for(int cur=0;cur<nums.size();cur++)
        {
            if(nums[cur]!=0)
            {
                swap(nums[cur],nums[++dest]);
            }
        }    
    }
};